﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CRMFramework;
using System.Data;

namespace CRMEntity
{
    public class Application
    {
        public Int32 app_id { get; set; }
        public Int32 ContactID { get; set; }
        public string CombineApp { get; set; }
        public string deletedFlag { get; set; }
        public string app_result { get; set; }
        public string LoadNo { get; set; }
        public string Folder { get; set; }
        public int NoInApplication { get; set; }
        public int NoInApplications { get; set; }
        public string OfferedAmount { get; set; }
        public string DesiredAmount { get; set; }
        public string amountMoto { get; set; }
        public string amoutProperties { get; set; }
        public string TextAwaitDoc { get; set; }
        public string PurposeSummary { get; set; }
        public string Memo { get; set; }
        public int LenderID { get; set; }
        public string OutSrcLenderVal { get; set; }
        public string LoanStatus { get; set; }
        public int ReferrerID { get; set; }
        public string ReferrerVal { get; set; }
        public string CreatedDate { get; set; }
        public string EditDate { get; set; }
        public string comesfrom { get; set; }
        public string securities { get; set; }
        public string IsUSB { get; set; }
        public int IsCarOwner { get; set; }
        public string Operator { get; set; }

        public Application() { }


        public DataSet AddNewApplicationProfile()
        {
            DataSet ds;
            try
            {
                var para = new[] {
                    DBhelper.SetParameter("@p_ContactID",ContactID),
                    DBhelper.SetParameter("@p_NoInApplication",NoInApplication),
                    DBhelper.SetParameter("@p_CombineApp",CombineApp),
                    DBhelper.SetParameter("@p_app_LoanAmount",DesiredAmount),
                    DBhelper.SetParameter("@p_OfferedAmount",OfferedAmount),
                    DBhelper.SetParameter("@p_app_result",app_result),
                    DBhelper.SetParameter("@p_LoadNo",LoadNo),
                    DBhelper.SetParameter("@p_NoInApplications",NoInApplications),
                    DBhelper.SetParameter("@p_Folder",Folder),
                    DBhelper.SetParameter("@p_amountMoto",amountMoto),
                    DBhelper.SetParameter("@p_amoutProperties",amoutProperties),
                    DBhelper.SetParameter("@p_TextAwaitDoc",TextAwaitDoc),
                    DBhelper.SetParameter("@p_purposeSummary", PurposeSummary),
                    DBhelper.SetParameterForApp("@p_Memo",Memo),
                    DBhelper.SetParameterForApp("@p_OutSrcLenderVal",OutSrcLenderVal),
                    DBhelper.SetParameterForApp("@p_ReferrerVal",ReferrerVal),
                    DBhelper.SetParameterForApp("@p_LoanStatus",LoanStatus),
                    DBhelper.SetParameter("@p_Operator",Operator),
                    DBhelper.SetParameter("@p_IsCarOwner",IsCarOwner),
                };

                ds = DBhelper.ExecuteDatasetSP("sp_addNewApplicationProfile", para);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return ds;
        }

        /// <summary>
        /// function for update Application Profile data and Save History
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool UpdateAppDetailData()
        {
            bool flag = false;
            string sql = string.Empty;

            try
            {
                var param = new[] {
                    DBhelper.SetParameter("@p_appID", app_id),
                    DBhelper.SetParameter("@p_app_result", app_result),
                    DBhelper.SetParameter("@p_LoadNo", LoadNo),
                    DBhelper.SetParameter("@p_NoInApplication", 1),
                    DBhelper.SetParameterForApp("@p_Folder",Folder),
                    DBhelper.SetParameter("@p_OfferedAmount",OfferedAmount),
                    DBhelper.SetParameterForApp("@p_DesiredAmount",DesiredAmount),
                    DBhelper.SetParameter("@p_amountMoto",amountMoto),
                    DBhelper.SetParameterForApp("@p_amoutProperties",amoutProperties),
                    DBhelper.SetParameterForApp("@p_TextAwaitDoc",TextAwaitDoc),
                    DBhelper.SetParameterForApp("@p_purposeSummary",PurposeSummary),
                    DBhelper.SetParameterForApp("@p_Memo",Memo),
                    DBhelper.SetParameterForApp("@p_OutSrcLenderVal",OutSrcLenderVal),
                    DBhelper.SetParameterForApp("@p_ReferrerVal",ReferrerVal),
                    DBhelper.SetParameterForApp("@p_Operator",Operator),
                    DBhelper.SetParameterForApp("@p_IsCarOwner",IsCarOwner),
                    DBhelper.SetParameterForApp("@p_LoanStatus",LoanStatus),
                };
                DBhelper.ExecuteNonQuerySP("sp_UpdateApplicationProfile", param);
                flag = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return flag;
        }


    }
}
